#include "BoneList.h"
#include "Bone.h"

BoneList::BoneList()
{
	head = NULL;
}
BoneList::BoneList(Bone * headBone)
{
	head = new List<Bone>(headBone, NULL);
}
	
BoneList::~BoneList()
{
	printf("Deleting bone list\n");
	List<Bone> * search = head;
	while(search)
	{
		search = search->Remove();
	}
	printf("Done deleting bone list\n");
	head = NULL;
}
	
void BoneList::Add(Bone * payload)
{
	head =  new List<Bone>(payload, head);
}
void BoneList::Think(double elapsedTime)
{
	List<Bone> * search = head;
	while(search)
	{
		if(search->payload)
			search->payload->Think(elapsedTime);
		search = search->next;
	}
}
void BoneList::Draw()
{
	List<Bone> * search = head;
	while(search)
	{
		if(search->payload)
			search->payload->Draw();
		search = search->next;
	}
}

bool BoneList::CheckOrientation()
{
	List<Bone> * search = head;
	while(search)
	{
		if(search->payload && !search->payload->CheckAllOrientation())
		{
			return false;
		}
		search = search->next;
	}
	return true;
}
void BoneList::SetModifiers(float angleModifier, float lengthModifier, float timeModifier)
{
	List<Bone> * search = head;
	while(search)
	{
		if(search->payload)
		{
			search->payload->SetModifiers(angleModifier,lengthModifier,timeModifier);
		}
		search = search->next;
	}
}
void BoneList::SetDesiredOrientation(BoneOrientationNodeList * desiredList)
{
	List<Bone> * search = head;
	List<BoneOrientationNode> * nodeSearch = desiredList->GetHead();
	while(search && nodeSearch)
	{
		if(search->payload && nodeSearch->payload)
		{
			search->payload->SetDesiredOrientation(nodeSearch->payload->GetOrientation());
			BoneList * outgoingBones = search->payload->GetOutgoingBoneList();
			if(outgoingBones)
				outgoingBones->SetDesiredOrientation(nodeSearch->payload->GetOutgoingNodeList());
		}
		search = search->next;
		nodeSearch = nodeSearch->next;
	}	
	
}
